package com.lk.springboot.dao;

import com.lk.springboot.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author lk
 * @date 2020/3/5 0005 12:34
 */
@Mapper
public interface HomeMapper {

    // 获取我的道具列表
    @Select("select props.props_id,props_name,num from props,user_props where u_id = #{u_id} and user_props.props_id = props.props_id")
    List<MyProps> getMyProps(String u_id);

    // 获取用户道具拥有数目
    @Select("select num from user_props where u_id = #{u_id} and props_id = #{props_id}")
    int getPropsNum(@Param("u_id") String u_id, @Param("props_id") int props_id);

    // 减少用户获得的道具数目
    @Update("update user_props set num = num - 1 where u_id = #{u_id} and props_id = #{props_id} and num >= 0")
    void reducePropsNum(@Param("u_id") String u_id, @Param("props_id") int props_id);

    // 获取我的主页信息（用户名，赞数，浏览数）
    @Select(" select u_name,likes,views from users where u_id=#{u_id}")
    Mine getMine(String u_id);

    // 增加浏览数
    @Update("uodate users set views = views + 1 where u_id = #{u_id}")
    void addViews(String u_id);

    // 增加点赞数
    @Update("update users set likes = likes + 1 where u_id = #{u_id}")
    void addLikes(String u_id);

    // 获取点赞数
    @Select("select likes from users where u_id = #{u_id}")
    int getLikes(String u_id);

    // 获取用户现有拼图的 s_id，sp_id 和 数量num
    @Select("select s_id, sp_id, count(*) as num from u_s_have where u_id = #{u_id} group by sp_id")
    List<MySmallPhoto> getAllMySP(String u_id);

    // 根据站点s_id 获取站点名称
    @Select("select s_name from sites where s_id = #{s_id}")
    String getSitesName(String s_id);

    // 根据拼图碎片sp_id 获取拼图地址url , tags
    @Select("select url,tags from smallphoto where sp_id = #{sp_id}")
    TheSiteSP getTheSiteSP(String sp_id);

    // 获取用户捐赠列表（um_id,place,date）
    @Select("select umbrella.um_id, place, date from umbrella,donate_um where u_id = #{u_id} and umbrella.um_id = donate_um.um_id")
    List<MyUmbrella> getMyUmbrella(String u_id);

    // 获取用户名
    @Select("select u_name from users where u_id=#{u_id}")
    String getUserName(String u_id);

    // 新消息已读，更改通知状态为无新消息（0无，1有）
    @Update("update users set news = 0 where u_id = #{u_id}")
    void updateNewsNo(String u_id);

    // 获取是否有新消息(消息状态)
    @Select("select news from users where u_id = #{u_id}")
    int getNews(String u_id);

}
